/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Tools;

import java.util.ArrayList;

/**
 *
 * @author patricksamson236
 */
public class Settings {

    private ArrayList<String> default_name = new ArrayList<String>();
    private ArrayList default_value = new ArrayList();
    private ArrayList<String> name = new ArrayList<String>();
    private ArrayList value = new ArrayList();
    private FileTools filetools = new FileTools();

    public Settings() {
        setup_defaults();
    }

    private void setup_defaults() {
        default_name.add("version");
        default_value.add("v0.1");

        default_name.add("httpnumworkers");
        default_value.add(10);

        default_name.add("httpbuffersize");
        default_value.add(4 * 1024);

        default_name.add("http_dest");
        default_value.add(filetools.getScitnerDownDir());

        default_name.add("torr_dest");
        default_value.add(filetools.getScitnerDownDir());
    }

    public void reset_settings() {
        name = default_name;
        value = default_value;
    }

    private void upgrade_version() {
        // if versions are different
        if (!value.get(name.indexOf("version")).equals(default_value.get(default_name.indexOf("version")))) {
            //update current version value
            value.set(name.indexOf("version"), default_value.get(default_name.indexOf("version")));

            //add new settings
            for (int i = 0; i < default_name.size(); i++) {
                if (!name.contains(default_name.get(i))) {
                    name.add(default_name.get(i));
                    value.add(default_value.get(i));
                }
            }

            //remove the old ones, if necessary
            if (name.size() != default_name.size()) {
                for (int i = 0; i < name.size(); i++) {
                    if (!default_name.contains(name.get(i))) {
                        name.remove(i);
                        value.remove(i);
                        i--;
                    }
                }
            }
        }
    }

    public ArrayList getNames() {
        return name;
    }

    public ArrayList getValues() {
        return value;
    }

    public void loadSettings(ArrayList<String> name, ArrayList value) {
        this.name = name;
        this.value = value;
        upgrade_version();
    }

    public int getHttpNumWorkers() {
        int httpNumWorkers = (Integer) value.get(name.indexOf("httpnumworkers"));
        return httpNumWorkers;
    }

    public void setHttpNumWorkers(int httpNumWorkers) {
        value.set(name.indexOf("httpnumworkers"), httpNumWorkers);
    }

    public int getHttpBufferSize() {
        int httpBufferSize = (Integer) value.get(name.indexOf("httpbuffersize"));
        return httpBufferSize;
    }

    public void setHttpBufferSize(int httpBufferSize) {
        value.set(name.indexOf("httpbuffersize"), httpBufferSize);
    }

    public String getHttpDestination() {
        String httpDestination = (String) value.get(name.indexOf("http_dest"));
        return httpDestination;
    }
    
    public void setHttpDestination(String httpDestination){
        value.set(name.indexOf("http_dest"), httpDestination);
    }

    public String getTorrDestination() {
        String torrDestination = (String) value.get(name.indexOf("torr_dest"));
        return torrDestination;
    }
    
    public void setTorrDestination(String torrDestination){
        value.set(name.indexOf("torr_dest"), torrDestination);
    }
}
